﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace card
{
    public partial class XPLISTForm : Form
    {
        public static WebDG.Service ws = new card.WebDG.Service();
        public XPLISTForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            load_data();
        }
        private void load_data()
        {

            string sql = " select XPBH as 小票号, logintime as 登记时间,SHIPNAME as 船名,BILL_NO as 提单号,cargoname as 货名,truckno as  车号,pieces as 件数,STACKNAME as 垛名,PACKAGE as 包装,LXH as 流向号,DYCS as 打印次数,DYRQ AS 打印日期 from TRUCK_CARGO_LOGIN_XPDY";

            string str_xph = this.tb_xph.Text.ToString();
            string str_cph = this.tb_cph.Text.ToString();
            string str_tdh = this.tb_tdh.Text.ToString();
            string str_dyrqbegin = this.dtp_begin.Value.ToString("yyyy-MM-dd");
            string str_dyrqend = this.dtp_end.Value.ToString("yyyy-MM-dd");
            sql += " where CARDADD ='" + card_add + "' AND DYRQ>=to_date('" + str_dyrqbegin + "','yyyy-mm-dd') and  DYRQ<=to_date('" + str_dyrqend + "','yyyy-mm-dd')  ";
            if (!str_xph.Equals(""))
            {
                sql += " and XPBH like '%" + str_xph + "%'";
            }
            if (!str_cph.Equals(""))
            {
                sql += " and truckno like '%" + str_cph + "%'";
            }
            if (!str_tdh.Equals(""))
            {
                sql += " and BILL_NO like '%" + str_tdh + "%'";
            }
            sql += " order by DYRQ desc ";
            DataSet ds = ws.getDataSet_Serv(sql);
            this.dataGridView1.AutoGenerateColumns = true;
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.DataSource = ds.Tables[0];

            ////设置某些字段不可见
            //this.dataGridView1.Columns["IOYARDID"].Visible = false;
            //this.dataGridView1.Columns["TRUCKSTATUS"].Visible = false;
            //this.dataGridView1.Columns["id"].Visible = false;
            //this.dataGridView1.Columns["DYBZ"].Visible = false;
        }
        string card_add = "";
        private void XPLISTForm_Load(object sender, EventArgs e)
        {
            card_add = System.Configuration.ConfigurationSettings.AppSettings["card_address"];

            load_data();
        }
        string Str_ID = "";
        private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                DataGridViewRow dataGridViewRow1 = dataGridView1.Rows[e.RowIndex];
                dataGridView1.ClearSelection();
                dataGridViewRow1.Selected = true;
                Str_ID = dataGridViewRow1.Cells["小票号"].Value.ToString();
              
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //PrinForm2 pf = new PrinForm2(Str_ID, "大港公司市提市入车辆登记小票");
            //pf.Show();

            //string strid = this.dataGridView1.Rows[i].Cells["编号"].Value.ToString();
            PrintCode pc = new PrintCode();
            pc.Run2(Str_ID, "大港公司市提市入车辆登记小票");

        }
    }
}
